<extend name='Public/demo' />

<block name="contents">
    <div class="row">
                      <div class="col-lg-12">
                          <section class="panel">
                              <header class="panel-heading">
                                  权限分组 <a class="btn btn-success pull-right btn-xs " href="{:U('Competence/add')}">添加用户组</a>
                              </header>
                              <table class="table table-striped table-advance table-hover">
                                  <thead>
                                  <tr>
                                      <th class="col-md-2"><i class="icon-bullhorn"></i> 用户组名称</th>
                                      <th class="hidden-phone col-md-7"><i class="icon-question-sign"></i> 用户组成员</th>
                                      <th class="col-md-3">操作</th>
                                  </tr>
                                  </thead>
                                  <tbody>

                                    <?php foreach($res as $val){ ?>
                                    <tr>
                                        <td><a href="#"><?php echo $val['title'] ?></a></td>
                                        <td class="getadmin" data="<?php echo $val['id'] ?>"></td>  <!-- 多个成员用' | '分隔 -->
                                        <td>
                                            <a class="btn btn-primary btn-xs" href="{:U('Competence/edit')}?id=<?php echo $val['id'] ?>"><i class="icon-pencil"></i> 编辑权限 </a>
                                            <button class="btn btn-danger btn-xs delg" data="<?php echo $val['id'] ?>"><i class="icon-trash "></i> 删除管理组</button><!-- 只有当用户组没有成员的时候 才可以使用删除按钮 -->
                                        </td>
                                    </tr>
                                    <?php } ?>
                                  </tbody>
                              </table>
                          </section>
                      </div>
                  </div>
                  <script type="text/javascript">
                      $('.getadmin').each(function(){
                        //得到当前的元素对象
                        var th = $(this);
                        //得到当前的用户组ID
                        var id = $(this).attr('data');
                        $.post("{:U('Competence/getadmin')}",{id:id},function(data){
                            th.html(data);
                        });
                      });
                      //删除管理员组
                      $('.delg').click(function(){
                        //得到当前要删除的管理员组的ID
                        var id = $(this).attr('data');
                        //得到当前的元素对象
                        var th = $(this);
                        //修改按钮文字
                        $(this).html('<i class="icon-trash "></i> 正在删除~')
                        //发送ajax
                        $.post("{:U('Competence/delg')}",{id:id},function(data){
                          th.html('<i class="icon-trash "></i> '+data);
                          //刷新网页
                          setTimeout(function(){
                            location.href = location.href;
                          },1000)
                        })
                      });
                  </script>
</block>
